//
//  TaskProcessTableViewCell.m
//  OAProject
//
//  Created by yhj on 2017/3/9.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "TaskProcessTableViewCell.h"

@interface TaskProcessTableViewCell ()

@property(nonatomic,strong)UIView *bgView;

// 流程名字
@property(nonatomic,strong)UILabel *taskProgressDetailLabel;

// 流程表述
@property(nonatomic,strong)UILabel *taskProgressNameLabel;

// 负责人名字
@property(nonatomic,strong)UILabel *nameLabel;

// 截止时间
@property(nonatomic,strong)UILabel *deadLineLabel;

// 编辑
@property(nonatomic,strong)UIButton *editBtn;

// 删除
@property(nonatomic,strong)UIButton *deleteBtn;

@property(nonatomic,strong)UIView *selectView;

@property(nonatomic,strong)UIButton *delBtn;

@end

@implementation TaskProcessTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.taskProgressNameLabel.font=Font_Number(16);

        self.taskProgressDetailLabel.font=Font_Number(16);

        self.nameLabel.font=Font_Number(16);

        self.deadLineLabel.font=Font_Number(16);

        self.editBtn.hidden=NO;

        self.deleteBtn.hidden=NO;

        self.topLine.hidden=NO;

        self.bottomLine.hidden=NO;

        self.bgView.hidden=NO;

        self.delBtn.hidden=NO;

        self.backgroundColor=WhiteColor;

//        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapEvent)];
//        [self addGestureRecognizer:tap];

    }
    return self;
}

//-(void)tapEvent
//{
//    _selectView=[UIView new];
//    [self.contentView addSubview:self.selectView];
//    _selectView.backgroundColor=BGColor;
//    [_selectView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(self.bgView.mas_centerX);
//        make.top.mas_equalTo(self.taskProgressNameLabel.mas_bottom).offset(kmargin);
//        make.bottom.mas_equalTo(self.deadLineLabel.mas_bottom);
//        make.right.mas_equalTo(0);
//    }];
//
//    UIButton *deleteBtn=[AppUI createButtonWithSupeView:self.selectView andWithNormalImage:[UIImage imageNamed:@"DeleteIcon"] andWithSelectImage:[UIImage imageNamed:@"DeleteIcon"] andWithBtnAction:^{
//
//        if (self.delegate&&[self.delegate respondsToSelector:@selector(deleteTaskProcessWithTaskProgressModel:cell:)])
//        {
//            [self.delegate deleteTaskProcessWithTaskProgressModel:self.model cell:self];
////             self.selectView.hidden=YES;
//        }
//    }];
//    deleteBtn.frame=CGRectMake(APPW/2-kmargin*12,kmargin*2,kmargin*4,kmargin*3);
//    [self.selectView addSubview:deleteBtn];
//
//
//
//    UIButton *editBtn=[AppUI createButtonWithSupeView:self.selectView andWithNormalImage:[UIImage imageNamed:@"EditIcon"] andWithSelectImage:[UIImage imageNamed:@"EditIcon"] andWithBtnAction:^{
//
//        if (self.delegate&&[self.delegate respondsToSelector:@selector(editTaskProcessWithTaskProgressModel:cell:)])
//        {
//            [self.delegate editTaskProcessWithTaskProgressModel:self.model cell:self];
//
////            self.selectView.hidden=YES;
//        }
//    }];
//    editBtn.frame=CGRectMake(APPW/2,kmargin*2,kmargin*4,kmargin*3);
//    [self.selectView addSubview:editBtn];
//}


-(UIView *)topLine
{
    if (!_topLine) {
        _topLine=[UIView new];
        _topLine.backgroundColor=[UIColor lightGrayColor];
        [self.contentView addSubview:_topLine];
        [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.bgView.mas_centerX);
            make.width.mas_equalTo(1);
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(self.bgView.mas_top);
        }];
    }
    return _topLine;
}

// bottomLine
-(UIView *)bottomLine
{
    if (!_bottomLine) {
        _bottomLine=[UIView new];
        _bottomLine.backgroundColor=[UIColor lightGrayColor];
        [self.contentView addSubview:_bottomLine];
        [_bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.bgView.mas_centerX);
            make.width.mas_equalTo(1);
            make.top.mas_equalTo(self.bgView.mas_bottom);
            make.bottom.mas_equalTo(0);
        }];
    }
    return _bottomLine;
}

// bgView
- (UIView *)bgView
{
    if (!_bgView) {
        _bgView=[UIView new];
        ViewBorderRadius(_bgView,kmargin,1,ClearColor);
        [self.contentView addSubview:_bgView];
        _bgView.backgroundColor=[UIColor redColor];
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*4);
            make.top.mas_equalTo(kmargin*2);
            make.size.mas_equalTo(CGSizeMake(kmargin*2,kmargin*2));
        }];
    }
    return _bgView;
}

// taskProgressNameLabel
- (UILabel *)taskProgressNameLabel
{
    if (!_taskProgressNameLabel) {
        _taskProgressNameLabel=[self getLabelWithText:@"流程A" font:Font_Number(16) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_taskProgressNameLabel];
        [_taskProgressNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.bgView.mas_centerY);
            make.left.mas_equalTo(self.bgView.mas_right).offset(kmargin);
        }];
    }
    return _taskProgressNameLabel;
}

// taskProgressDetailLabel
- (UILabel *)taskProgressDetailLabel
{
    if (!_taskProgressDetailLabel) {
        _taskProgressDetailLabel=[self getLabelWithText:@"主机错误分析细连接时间 首包时间 " font:Font_Number(16) textColor:LightGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_taskProgressDetailLabel];
        [_taskProgressDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.taskProgressNameLabel.mas_bottom).offset(kmargin);
            make.left.mas_equalTo(self.taskProgressNameLabel.mas_left);
            make.right.mas_equalTo(-kmargin);
        }];
    }
    return _taskProgressDetailLabel;
}

// nameLabel
- (UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel=[self getLabelWithText:@"负责人:龙云 龙江" font:Font_Number(16) textColor:LightGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.taskProgressDetailLabel.mas_bottom).offset(kmargin);
            make.left.mas_equalTo(self.taskProgressNameLabel.mas_left);
            make.right.mas_equalTo(-kmargin);
        }];
    }
    return _nameLabel;
}

// deadLineLabel
- (UILabel *)deadLineLabel
{
    if (!_deadLineLabel) {
        _deadLineLabel=[self getLabelWithText:@"截止时间:2017年3月20日 18:00" font:Font_Number(16) textColor:LightGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_deadLineLabel];
        [_deadLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(kmargin);
            make.left.mas_equalTo(self.taskProgressNameLabel.mas_left);
            make.right.mas_equalTo(-kmargin);
        }];
    }
    return _deadLineLabel;
}

// delBtn
-(UIButton *)delBtn
{
    if (!_delBtn) {
        _delBtn=[AppUI createButtonWithSupeView:self.contentView andWithNormalImage:[UIImage imageNamed:@"DeleteIcon"] andWithSelectImage:[UIImage imageNamed:@"DeleteIcon"] andWithBtnAction:^{

            if (self.delegate&&[self.delegate respondsToSelector:@selector(deleteTaskProcessWithTaskProgressModel:cell:)]) {
                [self.delegate deleteTaskProcessWithTaskProgressModel:self.model cell:self];
            }
        }];
        [self.contentView addSubview:_delBtn];
        [self.delBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(kmargin*3,kmargin*3));
            make.left.mas_equalTo(self.deadLineLabel.mas_left).offset(kmargin);
            make.top.mas_equalTo(self.deadLineLabel.mas_bottom).offset(kmargin);
        }];
    }
    return _delBtn;
}

-(UIButton *)editBtn
{
    if (!_editBtn) {
        _editBtn=[AppUI createButtonWithSupeView:self.contentView andWithNormalImage:[UIImage imageNamed:@"EditIcon"] andWithSelectImage:[UIImage imageNamed:@"EditIcon"] andWithBtnAction:^{

            if (self.delegate&&[self.delegate respondsToSelector:@selector(editTaskProcessWithTaskProgressModel:cell:)]) {
                [self.delegate editTaskProcessWithTaskProgressModel:self.model cell:self];
            }
        }];
        [self.contentView addSubview:_editBtn];
        [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(kmargin*3,kmargin*3));
            make.right.mas_equalTo(-APPW/4);
            make.top.mas_equalTo(self.delBtn.mas_top);
        }];
    }
    return _editBtn;
}

-(void)setModel:(TaskProgressModel *)model
{
    _model=model;

    self.bgView.backgroundColor=([model.is_done isEqualToString:@"1"])?MainColor:LightGreyColor;

    self.bottomLine.backgroundColor=([model.is_done isEqualToString:@"1"])?MainColor:LightGreyColor;

    self.topLine.backgroundColor=([model.is_done isEqualToString:@"1"])?MainColor:LightGreyColor;

    self.taskProgressNameLabel.text=model.title;

    self.taskProgressNameLabel.textColor=([model.is_done isEqualToString:@"1"])?MainColor:DarkGreyColor;
    self.taskProgressDetailLabel.text=model.descriptionStr;

    if ([model.user_id isEqualToString:@"0"])
    {
      self.nameLabel.text=[NSString stringWithFormat:@"执行人:%@",model.user_name];
        NSLog(@"7877666500---%@", model.old_user_ids[0]);
        NSString *userID= model.old_user_ids[0];

        NSString *userName=[model.old_user_names objectForKey:userID];

        self.nameLabel.text=[NSString stringWithFormat:@"执行人:%@等",userName];
    }
    else
    {
      self.nameLabel.text=[NSString stringWithFormat:@"执行人:%@",model.user_name];
    }
    self.deadLineLabel.text=[NSString stringWithFormat:@"截止时间:%@",model.estimate_etime];
    
}

@end
